package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.Student;
import com.example.entity.ReturnVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface StudentMapper extends BaseMapper<Student> {


    /**
     * 注解模式
     * @param id
     * @return
     */
    @Select("SELECT * FROM student where id =#{id}")
    Student selectSql(@Param("id") int id);


    @Select("<script>" +
            "select s.id,s.age,s.name,t.tname tname ,t.job " +
            "from student s inner JOIN teacher t " +
            "on s.tid=t.tid where 1=1" +
             "<if test='id != null'>"+
            "and s.id=#{id}" +
            "</if>" +
            "</script>")
    List<ReturnVo> selectVo(@Param("id") Integer id);

    @Select("<script>" +
            "select s.id,s.age,s.name,t.tname tname ,t.job " +
            "from student s inner JOIN teacher t " +
            "on s.tid=t.tid where 1=1" +
            "<if test='name!=null and  name!=&quot;&quot;'>" +
            "and name=#{name}" +
            "</if>" +
            "</script>")
    List<ReturnVo> selectNameVo(@Param("name")String name);


    @Select("<script>" +
            "select s.id,s.age,s.name,t.tname tname ,t.job " +
            "from student s inner JOIN teacher t " +
            "on s.tid=t.tid where 1=1" +
            "<if test='map.name!=null and  map.name!=&quot;&quot;'>" +
            "and name=#{map.name}" +
            "</if>" +
            "limit #{map.page},#{map.limit}" +

            "</script>")
    List<ReturnVo> selectMapVo(@Param("map")Map map);


    @Select("<script>" +
            "select s.id,s.age,s.name,t.tname tname ,t.job " +
            "from student s inner JOIN teacher t " +
            "on s.tid=t.tid where 1=1" +
            "<if test='vo.name!=null and  vo.name!=&quot;&quot;'>" +
            "and name=#{vo.name}" +
            "</if>" +
            "limit #{vo.page},#{vo.limit}" +
            "</script>")
    List<ReturnVo> selectPageVo(@Param("vo")ReturnVo vo);
}